/**
 * PackageDir: info.javafans.cdn.dao
 * FileName: ActivityDao.java
 * CreateDate: 2011-3-6 上午09:11:36
 * Copyright: Copyright (c) 2011 <br />
 * Company: fossd <br />
 * @author Yintao Xue
 * @version 1.0 2011-3-6
 */
package info.javafans.cdn.dao;

import info.javafans.cdn.database.DbHelper;
import info.javafans.cdn.domain.Activity;

import java.sql.SQLException;
import java.util.List;

import org.apache.log4j.Logger;

/**
 * Project: CollegeDatingNetwork <br />
 * ClassName: ActivityDao <br />
 * Description: <br />
 */
public class ActivityDao {
	public static Logger logger = Logger.getLogger(ActivityDao.class);

	public static List<Activity> selectLatestActivity() {
		String sql = "select * from activity order by activityCount desc limit 0,5";
		List<Activity> activityList = null;

		activityList = DbHelper.queryBeanList(Activity.class, sql, null);

		// 为每个活动设置发起人和所属社团
		for (Activity a : activityList) {
			a.setGroup(GroupDao.selectGroupById(a.getGroupId()));
			a.setSponsor(MemberDao.selectMemberById(a.getSponsorId()));
		}
		return activityList;
	}
	
	/**
	 * 按id查询活动
	 * selectActivityById
	 * @param id
	 * @return
	 */
	public static Activity selectActivityById(int id) {
		String sql = "select * from activity where id = ?";
		Activity a = DbHelper.queryBean(Activity.class, sql, id);
		
		a.setGroup(GroupDao.selectGroupById(a.getGroupId()));
		a.setSponsor(MemberDao.selectMemberById(a.getSponsorId()));
		
		return a;
	}
	
	/**
	 * 获取活动列表
	 * selectActivityList
	 * @return
	 */
	public static List<Activity> selectActivityList() {
		String sql = "select * from activity";
		List<Activity> activityList = DbHelper.queryBeanList(Activity.class, sql, null);
		// 为每个活动设置发起人和所属社团
		for (Activity a : activityList) {
			a.setGroup(GroupDao.selectGroupById(a.getGroupId()));
			a.setSponsor(MemberDao.selectMemberById(a.getSponsorId()));
		}
		return activityList;
	}
}
